<% layout('/layouts/default.html', {title: '报表管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa fa-list-alt"></i> (${startTime}至${endTime})${text('所有代理统计报表')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<% if(hasPermi('vip:member:edit')){ %>
					<a href="${ctx}/vip/member/form" class="btn btn-default btnTool" title="${text('新增会员')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
				<% } %>
				<div class="btn-group">
					<a href="javascript:" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
						<i class="fa fa-navicon"></i> <span class="caret"></span>
					</a>
					<ul class="dropdown-menu">
						<li><a href="javascript:" id="btnExport"><i class="glyphicon glyphicon-export"></i> 导出</a></li>
					</ul>
				</div>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${member}" action="${ctx}/vip/record/listAgentData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
			<div class="form-group">
					<label class="control-label">起始时间：</label>
					<div class="control-inline">
						<input id="startTime" name="startTime" value="${startTime}" readonly="readonly" maxlength="20" class="form-control Wdate-date"
						dataFormat="date" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false,onpicked:function(){createDate_lte.click()}});"/>
						&nbsp;--&nbsp;
						<input id="endTime" name="endTime" value="${endTime}" readonly="readonly" maxlength="20" class="form-control Wdate-date"
						dataFormat="date" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
					</div>
				</div>
				<div class="form-group">
					<button id="btn" type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
				</div>
			</#form:form>
			<div class="box-title" id="countTitle" style="padding:4px;text-align:center;font-size:20px;">
			</div>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>
<script>
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{header:'${text('账号')}', name:'loginName', index:'a.loginName', width:150, align:"center", frozen:true, formatter: function(val, obj, row, act){

		    return '<a href="${ctx}/vip/record/memberRecord?userCode='+row.userCode+'&startTime='+$('#startTime').val()+
				'&endTime='+$('#endTime').val()+ '" class="btnList" data-title="${text('所有会员流水账')}">'+(val||row.id)+'</a>';
		}},
        {header:'${text('代理名称')}', name:'name', index:'a.name', width:150, align:"center"},
        {header:'${text('出货')}', name:'out', index:'a.out', width:150, align:"center", formatter: function(val, obj, row, act){
                return formatNumber(val); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值，金额情况下设置0.00);
            }},
        {header:'${text('入货')}', name:'in', index:'a.in', width:150, align:"center", formatter: function(val, obj, row, act){
                return formatNumber(val); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值，金额情况下设置0.00);
            }},
		{header:'${text('积分')}', name:'points', index:'a.points', width:150, align:"center", formatter: function(val, obj, row, act){
                return formatNumber(val); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值，金额情况下设置0.00);
		}},
		{header:'${text('总充值')}', name:'rechargeTotal', index:'a.rechargeTotal', width:150, align:"center", formatter: function(val, obj, row, act){
                return formatNumber(val); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值，金额情况下设置0.00);
		}},
        {header:'${text('总支出')}', name:'payTotal', index:'a.payTotal', width:150, align:"center", formatter: function(val, obj, row, act){
                return formatNumber(val); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值，金额情况下设置0.00);
            }}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){
        buildCount(data.otherData);
	}
});
$('#btnExport').click(function(){
    js.ajaxSubmitForm($('#searchForm'), {
        url:'${ctx}/vip/record/listAgentData?exportCode=1',
        downloadFile:true
    });
});
$(document).ready(function(){
    $("#btn").click();
});
//统计数据标题
function buildCount(countData){
    if(countData == undefined){
        $('#countTitle').html("统计数据为空");
        return;
    }
    var inTitle ="总入货:"+formatNumber(countData.in)+"&nbsp&nbsp&nbsp";
    var outTitle ="总出货:"+formatNumber(countData.out)+"&nbsp&nbsp&nbsp";
    var rechargeTitle ="总充值:"+formatNumber(countData.rechargeTotal)+"&nbsp&nbsp&nbsp";
    var pointsTitle ="总积分:"+formatNumber(countData.points)+"&nbsp&nbsp&nbsp";
    var payTitle = "总支出:"+formatNumber(countData.payTotal)+"&nbsp&nbsp&nbsp";
    $('#countTitle').html(outTitle + inTitle + pointsTitle + rechargeTitle + payTitle);
}
</script>